<?php
function smarty_function_image($params, &$smarty)
{
	$strPath 		= isset($params['path']) ? $params['path'] : '';	
	$intType 		= isset($params['type']) ? $params['type'] : 1;	
	$intSmall		= isset($params['small']) ? $params['small'] : 0;	
	$strClass		= isset($params['class']) ? $params['class'] : '';
	$strAlt			= isset($params['alt']) ? $params['alt'] : '';
	$intUserId		= isset($params['userid']) ? $params['userid'] : 0;
	$intViewId		= isset($params['viewid']) ? $params['viewid'] : 0;
	$intId			= isset($params['id']) ? $params['id'] : 0;
	$intTip			= isset($params['tip']) ? $params['tip'] : 0;
	$strTitle		= isset($params['title']) ? $params['title'] : '';
	$strAttr		= isset($params['attr']) ? $params['attr'] : '';
	$intFortune		= isset($params['fortune']) ? $params['fortune'] : 0;
	$strDir			= '';
	$strFullPath	= '';
	$intReType		= 0;
	$objUser			= null;	
	if($intUserId > 0 && $intType == 1) {
		$objVfriendUser = new Vfriend_User();
		$objUser		= $objVfriendUser->getFull($intUserId);
		$strPath		= $objUser->image_path;
		$strTitle		= $objUser->fullnamevn;
		if($intViewId > 0) {
			$intReType	= $objVfriendUser->getRelationType($intUserId, $intViewId);
		}
		//return $intUserId . '---' . $intType . '---' . $intViewId . '----' . $intReType;
	}
	if($strPath != '') {
		if($intType == 1) {
			
			if(!$intSmall) {
				$strDir 		= DIR_AVATAR_FULL . $strPath;
				$strFullPath	= HOST_IMG_AVATAR_FULL . $strPath;
			}
			else {
				if($intSmall == 1) {
					$strDir 		= DIR_AVATAR_THUMB . $strPath;
					$strFullPath	= HOST_IMG_AVATAR_THUMB . $strPath;
				}
				elseif($intSmall == 2) {
					$strDir 		= DIR_AVATAR_SMALL . $strPath;
					$strFullPath	= HOST_IMG_AVATAR_SMALL . $strPath;
				}
			}
		}
		elseif($intType == 2) {
			if(!$intSmall) {
				$strDir 		= DIR_ALBUM_FULL . $strPath;
				$strFullPath	= HOST_IMG_ALBUM_FULL . $strPath;
			}
			else {
				if($intSmall == 1) {
					$strDir	 		= DIR_ALBUM_THUMB . $strPath;
					$strFullPath	= HOST_IMG_ALBUM_THUMB . $strPath;
				} 
				
			}
		}
		elseif($intType == 3) {
			if(!$intSmall) {
				$strDir 		= DIR_BLOG_FULL . $strPath;
				$strFullPath	= HOST_IMG_BLOG_FULL . $strPath;
			}
			else {
				if($intSmall == 1) {
					$strDir 		= DIR_BLOG_THUMB . $strPath;
					$strFullPath	= HOST_IMG_BLOG_THUMB . $strPath;
				} else {
					$strDir	 		= DIR_BLOG_SMALL . $strPath;
					$strFullPath	= HOST_IMG_BLOG_SMALL . $strPath;
				}				
			}
		}
		elseif($intType == 4) {
			$strDir 		= DIR_PRODUCT . $strPath;
			$strFullPath	= HOST_IMG_PRODUCT . $strPath;
		}
		elseif($intType == 5) {
			if(!$intSmall) {
				$strDir 		= DIR_NEWS_FULL . $strPath;
				$strFullPath	= HOST_IMG_NEWS_FULL . $strPath;
			}
			else {
				if($intSmall == 1) {
					$strDir 		= DIR_NEWS_THUMB . $strPath;
					$strFullPath	= HOST_IMG_NEWS_THUMB . $strPath;				
				}	
				elseif($intSmall == 2) {
					$strDir 		= DIR_NEWS_SMALL . $strPath;
					$strFullPath	= HOST_IMG_NEWS_SMALL . $strPath;				
				}				
			}
		}elseif($intType == 6) {
			if(!$intSmall) {
				$strDir 		= DIR_COVER_FULL . $strPath;
				$strFullPath	= HOST_IMG_COVER_FULL . $strPath;
			}
			else {
				if($intSmall == 1) {
					$strDir 		= DIR_COVER_THUMB . $strPath;
					$strFullPath	= HOST_IMG_COVER_THUMB . $strPath;				
				}	
				elseif($intSmall == 2) {
					$strDir 		= DIR_COVER_SMALL . $strPath;
					$strFullPath	= HOST_IMG_COVER_SMALL . $strPath;				
				}				
			}
		}
		elseif($intType == 7) {
			if(!$intSmall) {
				$strDir 		= DIR_PLACE_FULL . $strPath;
				$strFullPath	= HOST_IMG_PLACE_FULL . $strPath;
			}
			else {
				if($intSmall == 1) {
					$strDir 		= DIR_PLACE_THUMB . $strPath;
					$strFullPath	= HOST_IMG_PLACE_THUMB . $strPath;				
				}else {
					$strDir 		= DIR_PLACE_SMALL . $strPath;
					$strFullPath	= HOST_IMG_PLACE_SMALL . $strPath;	
				}
			} 
		}
	} else {
		if($intType == 1) {			
			if(!$intSmall) {
				$strPath 		= '130.jpg';
			}
			else {
				if($intSmall == 1) {
					$strPath 		= '130.jpg';
				}
				else {
					$strPath 		= '50.jpg';
				}
			}
			$strDir	 		= DIR_DEFAULT . $strPath;
			$strFullPath	= HOST_IMG_DEFAULT . $strPath;
		}
	}
	if(!file_exists($strDir)) {
		if(!$intSmall) 
			$strPath 		= 'error-150.jpg';
		else {
			if($intSmall == 1) {
				$strPath 	= 'error-130.jpg';
			}
			else {
				$strPath 	= 'error-50.jpg';
			}
		}
		$strFullPath	= HOST_IMG_DEFAULT . $strPath;
	}
	$smarty->assign('intTip',		$intTip);
	$smarty->assign('strAttr',		$strAttr);
	$smarty->assign('intType',		$intType);	
	$smarty->assign('intReType',	$intReType);
	$smarty->assign('intUserId',	$intUserId);
	$smarty->assign('intId',		$intId);
	$smarty->assign('strTitle',		$strTitle);
	$smarty->assign('strAlt',		$strAlt);
	$smarty->assign('strClass',		$strClass);
	$smarty->assign('strFullPath', 	$strFullPath);	
	$smarty->assign('intFortune',	$intFortune);
	if($objUser) {
		$smarty->assign('objUserForPlugins', 	$objUser);	
	}
	$smarty->display(ROOT_DIR . '/library/Vfriend/Plugins/Tpl/image.tpl');
}
?>
